﻿using FlyingEye.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using OpenId2Ids.Models;
using Volo.Abp.AspNetCore.Mvc;

namespace OpenId2Ids.Controllers
{
    /// <summary>
    /// 用户控制器
    /// </summary>
    [Route("api/users")]
    [Authorize]
    public class UserController : AbpController
    {
        private readonly UserInfoService _userInfoService;

        private readonly ControllerActionWrapperService _wrapperService;

        public UserController(UserInfoService userInfoService, ControllerActionWrapperService wrapperService)
        {
            _userInfoService = userInfoService;
            _wrapperService = wrapperService;
        }

        /// <summary>
        /// 获取用户信息
        /// </summary>
        [Route("{id}/user-name")]
        [HttpGet]
        public async Task<DefaultActionResult<UserInfo>> GetUserNameById(Guid id)
        {
            return await _wrapperService.InvokeAsync(async () =>
            {
                var userName = await _userInfoService.GetUserNameByIdAsync(id);

                return new UserInfo(userName);
            });
        }
    }
}
